package com.it.elmboot.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.it.elmboot.pojo.Orders;
import com.it.elmboot.pojo.User;
import com.it.elmboot.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orders")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    @PostMapping ("/createOrders")
    public int createOrders(@RequestBody Orders orders) throws JsonProcessingException {
//        System.out.println(orders);
        return ordersService.createOrders(orders);
    }

    @PostMapping("/getOrdersById")
    public Orders getOrdersById(@RequestBody Orders orders){

        return ordersService.getOrdersById(orders.getOrderId());
    }

    @PostMapping("/listOrdersByUserId")
    public List<Orders> listOrdersByUserId(@RequestBody User user){
        return ordersService.listOrdersByUserId(user.getUserId());
    }

}
